﻿namespace Mathmall.Administration.common
{
    public class R<T>
    {
        /// <summary>
        /// 状态码:0-成功，1-失败
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 返回信息
        /// </summary>
        public string? Message { get; set; } = null;

        /// <summary>
        /// 返回的数据
        /// </summary>
        public T? Data { get; set; }

        public R<T> Success()
        {
            R<T> r = new R<T>();
            r.Code = CodeConstant.Success;
            r.Message = MessageConstant.SUCCESS;
            return r;
        }

        public R<T> Success(T? data)
        {
            R<T> r = new R<T>();
            r.Code = CodeConstant.Success;
            r.Message = MessageConstant.SUCCESS;
            r.Data = data;
            return r;
        }

        public R<T> Success(string? message, T? data)
        {
            R<T> r = new R<T>();
            r.Code = CodeConstant.Success;
            r.Message = message;
            r.Data = data;
            return r;
        }

        public R<T> Error(int code, string? message)
        {
            R<T> r = new R<T>();
            r.Code = code;
            r.Message = message;
            return r;
        }

        public R<T> Error(int code, string? message, T? data)
        {
            R<T> r = new R<T>();
            r.Code = code;
            r.Message = message;
            r.Data = data;
            return r;
        }
    }
}
